package com.gitee.chili.leisure.core;

import com.gitee.chili.leisure.model.MessageCmdEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * DefaultMessageHandlerRegistry
 *
 * @author week solider
 * @since 2020.09.04
 */
@Slf4j
public class DefaultMessageHandlerRegistry implements MessageHandlerRegistry {


    /**
     * 消息处理器缓存
     */
    private final Map<MessageCmdEnum.Command, MessageHandler> handlers = new HashMap<>(128);


    @Override
    public void register(MessageCmdEnum.Command cmd, MessageHandler messageHandler) {
        handlers.put(cmd, messageHandler);
    }

    @Override
    public MessageHandler getHandler(MessageCmdEnum.Command cmd) {
        return handlers.get(cmd);
    }
}
